// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 贵阳巴士快运旅游有限公司
// +----------------------------------------------------------------------
//Author:SUXU<zsx317127523@163.com>
// +----------------------------------------------------------------------

/**
 * 验证小数点后两位及多个小数
 * money 金额
 */
export function isMoney(money) {
	var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
	if (reg.test(money)) {
		return true
	} else {
		return false
	}
}
export function isNumber(num) {
	if (num != 0) {
		var reg = /^\d+(?=\.{0,1}\d+$|$)/;
		if (reg.test(num)) {
			return true
		} else {
			return false
		}
	}
	else{
		return false
	}
}


/**
 * 验证手机号码
 * money 金额
 */
export function checkPhone(phone) {
	var reg = /^1(3|4|5|6|7|8|9)\d{9}$/
	if (reg.test(phone)) {
		return true
	} else {
		return false
	}
}

/**
 * 函数防抖 (只执行最后一次点击)
 * @param fn
 * @param delay
 * @returns {Function}
 * @constructor
 */
export const Debounce = (fn, t) => {
	const delay = t || 500
	let timer
	return function() {
		const args = arguments
		if (timer) {
			clearTimeout(timer)
		}
		timer = setTimeout(() => {
			timer = null
			fn.apply(this, args)
		}, delay)
	}
}

 export const DebounceNew = function(t, e, n) {
        var r, u, o, i, a, l = function l() {
            var f = +new Date() - i;
            f < e && f >= 0 ? r = setTimeout(l, e - f) : (r = null, n || (a = t.apply(o, u), 
            r || (o = u = null)));
        };
        return function() {
            o = this, u = arguments, i = +new Date();
            var f = n && !r;
            return r || (r = setTimeout(l, e)), f && (a = t.apply(o, u), o = u = null), a;
        };
    }

/**
 * 验证邮箱
 */
export function isEmailAvailable(emailInput) {
	var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	if (!myreg.test(emailInput)) {
		return false;
	} else {
		return true;
	}
}
